package com.jintian.smart.kernel.orm.entity;

/**
 * 字段数据类型，控制生成物理表列的数据类型
 */
public enum ColumnType {
	keyword("keyword"), wildcard("wildcard"), constant_keyword("constant_keyword"), text("text"), text_keyword(
			"text.keyword"), integer("integer"), long_("long"), double_("double"), float_("float"), date(
					"date"), geo_point("geo_point"), geo_shape(
							"geo_shape"), object("object"), nested("nested"), binary("binary"), boolean_("boolean");

	private final String type;

	private ColumnType(String type) {
		this.type = type;
	}

	public String getType() {
		return type;
	}

	public static ColumnType valueOfType(String type) {
		if (type == null)
			return null;
		for (ColumnType t : ColumnType.values()) {
			if (type.equals(t.type))
				return t;
		}
		throw new RuntimeException("不支持的ColumnType" + type);
	}

	public static ColumnType valueOfDataType(DataType type) {
		if (type == null)
			return ColumnType.keyword;
		switch (type) {
		case String:
		case Text:
			return ColumnType.text;
		case Integer:
			return ColumnType.integer;
		case Boolean:
			return ColumnType.boolean_;
		case Float:
			return ColumnType.double_;
		case DateTime:
		case Date:
		case Time:
			return ColumnType.date;
		case Blob:
			return ColumnType.binary;
		case Decimal:
			return ColumnType.double_;
		}
		throw new RuntimeException("不支持的DataType" + type);
	}
}
